package web.fabrimind.tas.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import web.fabrimind.common.annotation.Log;
import web.fabrimind.common.core.controller.BaseController;
import web.fabrimind.common.core.domain.AjaxResult;
import web.fabrimind.common.enums.BusinessType;
import web.fabrimind.tas.domain.MaterialOutboundApply;
import web.fabrimind.tas.service.IMaterialOutboundApplyService;
import web.fabrimind.common.utils.poi.ExcelUtil;
import web.fabrimind.common.core.page.TableDataInfo;

/**
 * 物料出库申请Controller
 *
 * @author zhihui
 * @date 2025-04-04
 */
@RestController
@RequestMapping("/tas/MaterialOutboundApply")
public class MaterialOutboundApplyController extends BaseController
{
    @Autowired
    private IMaterialOutboundApplyService materialOutboundApplyService;

    /**
     * 查询物料出库申请列表
     */
    @PreAuthorize("@ss.hasPermi('tas:MaterialOutboundApply:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaterialOutboundApply materialOutboundApply)
    {
        startPage();
        List<MaterialOutboundApply> list = materialOutboundApplyService.selectMaterialOutboundApplyList(materialOutboundApply);
        return getDataTable(list);
    }

    /**
     * 导出物料出库申请列表
     */
    @PreAuthorize("@ss.hasPermi('tas:MaterialOutboundApply:export')")
    @Log(title = "物料出库申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialOutboundApply materialOutboundApply)
    {
        List<MaterialOutboundApply> list = materialOutboundApplyService.selectMaterialOutboundApplyList(materialOutboundApply);
        ExcelUtil<MaterialOutboundApply> util = new ExcelUtil<MaterialOutboundApply>(MaterialOutboundApply.class);
        util.exportExcel(response, list, "物料出库申请数据");
    }

    /**
     * 获取物料出库申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('tas:MaterialOutboundApply:query')")
    @GetMapping(value = "/{applyId}")
    public AjaxResult getInfo(@PathVariable("applyId") Long applyId)
    {
        return success(materialOutboundApplyService.selectMaterialOutboundApplyByApplyId(applyId));
    }

    /**
     * 新增物料出库申请
     */
    @PreAuthorize("@ss.hasPermi('tas:MaterialOutboundApply:add')")
    @Log(title = "物料出库申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialOutboundApply materialOutboundApply)
    {
        return toAjax(materialOutboundApplyService.insertMaterialOutboundApply(materialOutboundApply));
    }

    /**
     * 修改物料出库申请
     */
    @PreAuthorize("@ss.hasPermi('tas:MaterialOutboundApply:edit')")
    @Log(title = "物料出库申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialOutboundApply materialOutboundApply)
    {
        return toAjax(materialOutboundApplyService.updateMaterialOutboundApply(materialOutboundApply));
    }

    /**
     * 删除物料出库申请
     */
    @PreAuthorize("@ss.hasPermi('tas:MaterialOutboundApply:remove')")
    @Log(title = "物料出库申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{applyIds}")
    public AjaxResult remove(@PathVariable Long[] applyIds)
    {
        return toAjax(materialOutboundApplyService.deleteMaterialOutboundApplyByApplyIds(applyIds));
    }
}
